package com.asiainfo_linkage.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.service.EntityService;

import com.asiainfo_linkage.model.Sample;
import com.asiainfo_linkage.vo.SampleQuery;

@IocBean
public class SampleService extends EntityService<Sample>{
	
	@Inject
	protected Dao dao;
	
	public List<Sample> pageQuery(SampleQuery sampleQuery, Pager pager){
		if(sampleQuery==null){
			sampleQuery = new SampleQuery();
		}
		if(pager==null){
			pager = new Pager();
		}
		Criteria cri = Cnd.cri();
		if(!StringUtils.isEmpty(sampleQuery.getName())){
			cri.where().andLike("name", sampleQuery.getName()+"%", true);
		}
		if(!StringUtils.isEmpty(sampleQuery.getRemark())){
			cri.where().andLike("remark", sampleQuery.getRemark()+"%", true);
		}
		if(sampleQuery.getCreateTimeFrom()!=null){
			cri.where().and("createTime", ">=", sampleQuery.getCreateTimeFrom());
		}
		if(sampleQuery.getCreateTimeTo()!=null){
			cri.where().and("createTime", "<=", sampleQuery.getCreateTimeTo());
		}
		
		pager.setRecordCount(this.dao().count(Sample.class, cri));
		return this.dao().query(Sample.class, cri, pager);
	}


}
